package com.czxy.servlet;

import cn.itcast.servlet.BaseServlet;
import com.czxy.domain.Product;
import com.czxy.domain.ProductVo;
import com.czxy.service.ProductService;
import com.github.pagehelper.PageInfo;

import javax.servlet.annotation.WebServlet;

@WebServlet("/productServlet")
public class ProductServlet extends BaseServlet {

    public String findProductByVo(){
        //1.获取前端传递的参数
//        Product product = toBean(Product.class);
        ProductVo productVo = toBean(ProductVo.class);
//        productVo.setProduct(product);


        // 获取页码
        String pageNum = getRequest().getParameter("pageNum");
        int pageSize = 6;

        //2.调用Service获取结果
        ProductService service = new ProductService();
        PageInfo pageInfo = service.findProductsByVo(productVo, Integer.parseInt(pageNum), pageSize);
        //3.转存到request域, 请求转发给list.jsp
        getRequest().setAttribute("pageInfo", pageInfo);
        getRequest().setAttribute("productVo", productVo);
        return "/jsp/product_list.jsp";
    }
}
